<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">编号</label>
        <div class="layui-input-block">
            <input type="text" name="number" id="number" lay-verify="required" lay-reqtext="编号不得为空" placeholder="请输入编号"
                   value="" class="layui-input">
            <tip>填写产品分类的编号</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入产品分类名称"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">最低参考价格(元)</label>
        <div class="layui-input-block">
            <input type="number" name="minimum" id="minimum" lay-verify="required" lay-reqtext="最低参考价格不能为空"
                   placeholder="请输入最低参考价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">最高参考价格(元)</label>
        <div class="layui-input-block">
            <input type="number" name="highest" id="highest" lay-verify="required" lay-reqtext="最高参考价格不能为空"
                   placeholder="请输入最高参考价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">结算价格(元)</label>
        <div class="layui-input-block">
            <input type="number" name="settlementPrice" id="settlementPrice" lay-verify="required"
                   lay-reqtext="结算价格不能为空" placeholder="请输入结算价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">一级分销</label>
        <div class="layui-input-block">
            <input type="text" name="previousProfit" id="previousProfit" placeholder="请输入一级分销" lay-reqtext="一级分销不能为空"
                   value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">二级分销</label>
        <div class="layui-input-block">
            <input type="text" name="previousTwoProfit" id="previousTwoProfit" placeholder="请输入二级分销"
                   lay-reqtext="二级分销不能为空" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">计量单位</label>
        <div class="layui-input-block">
            <input type="text" name="measure" id="measure" placeholder="请选择计量单位"
                   lay-reqtext="计量单位不能为空" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label required">图标</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>点击上传
            </button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1">
                <p id="demoText"></p>
            </div>
            <tip>只能上传jpg/png文件，且不能超过500KB</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认提交</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            upload = layui.upload;

        //上传图片
        var uploadInst = upload.render({
            elem: '#test1', //绑定元素
            url: '/dhn/classify/uploadIcon/', //上传接口
            size: 500, //大小限制
            before: function (obj) {
                obj.preview(function (index, file, result) {
                    console.log(result)
                    $('#demo1').attr('src', result);
                });
            },
            done: function (res) {
                //上传完毕回调
                console.log(res)
            },
            error: function () {
                //请求异常回调
                console.log("网络错误！")
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                type: "post",
                url: "/dhn/classify/addMainClassify",
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(data.field),
                success: function (result) {
                    if (result.code == 0) {

                        layer.alert(result.result, {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        //parent.$("#shousuobtn",parent.document).trigger('click');	//子页面局部刷新父页面事件
                        window.parent.document.getElementById("shousuobtn").click();
                    }
                    console.info(result);
                },
                error: function () {
                    console.log("网络出错！请重新连接")
                }
            });

            return false;
        });

    });
</script>
</body>
</html>